package main

import (
	"fmt"
	"time"
)

func main() {
	c := make(chan bool)
	go func() {
		for i := 0; i < 5; i++ {
			time.Sleep(time.Second * 6)
			c <- false
		}
		time.Sleep(time.Second * 6)
		c <- true
	}()
	go func() {
		time.Sleep(time.Second*100)
		fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAA")
		for i := 0; i < 5; i++ {
			time.Sleep(time.Second * 6)
			c <- false
		}
		time.Sleep(time.Second * 6)
		c <- true
	}()
	go func() {
		timer := time.NewTimer(time.Second * 5)
		for {
			fmt.Println("===================")
			//计时器处于活动状态，未启动，stop始终返回true，不会出现任何问题
			stop := timer.Stop()
			fmt.Println(stop)
			if !stop {
				fmt.Println("stop")
				select {
				case <-timer.C: //try to drain from the channel
				default:
				}
			}
			timer.Reset(time.Second * 5)
			select {
			case b := <-c:
				if b == false {
					fmt.Println(time.Now(), ":recv false. continue")
					continue
				}
				fmt.Println(time.Now(), ":recv true. return")
				return
			case <-timer.C:
				fmt.Println(time.Now(), ":timer expired")
				continue
			}
		}
	}()
	var s string
	fmt.Scanln(&s)
}
